home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoMarkLargeObjOnPage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  6.0 KB  |  236 lines

  1. /*
  2.  *   $RCSfile: undoMarkLargeObjOnPage.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "pool.h"
  46. #include "tid.h"
  47. #include "io.h"
  48. #include "lock.h"
  49. #include "object.h"
  50. #include "msgdefs.h"
  51. #include "thread.h"
  52. #include "latch.h"
  53. #include "semaphore.h"
  54. #include "link.h"
  55. #include "lsn.h"
  56. #include "bf.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "logrecs.h"
  60. #include "openlog.h"
  61. #include "trans.h"
  62. #include "bitmap.h"
  63. #include "file.h"
  64. #include "consist.h"
  65. #include "undo.h"
  66. #include "io_extfuncs.h"
  67. #include "bf_extfuncs.h"
  68. #include "bm_extfuncs.h"
  69. #include "log_extfuncs.h"
  70. #include "undo_extfuncs.h"
  71. #include "logaction.h"
  72. #include "util_funcs.h"
  73. #include "thread_globals.h"
  74. #include "bf_globals.h"
  75.  
  76.  
  77.  void
  78. undoMarkLargeObjOnPage (
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     VOLREC                *volRec;
  85.     PID                    *pid;
  86.     FOUR                *markLoc;
  87.     SHORTPID            *key;
  88.     NODEPAGE            *nodePage;
  89.     GROUPLINK            *nodeLink;
  90.     LOGRECORDINFO        recordInfo;
  91.     FORCEMARK            forceMark;
  92.     LSN                    lsn;
  93.     SHORTPID            *gotPid;
  94.     LRC                    *lrc;
  95.     int                 i;
  96.     FOUR                foundLoc;
  97.  
  98.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
  99.  
  100.     /*
  101.      *    get a pointer to the pid in the record
  102.      */
  103.     pid = (PID *) &(recordHeader->actionPid);
  104.     TRPRINT(TR_IO, TR_LEVEL_2, ("pid:%d", pid->page));
  105.  
  106.     /*
  107.      *    get a pointer to the mark location in the record
  108.      */
  109.     markLoc = (FOUR *) GET_LOG_IMAGE(recordHeader, 0);
  110.     TRPRINT(TR_IO, TR_LEVEL_2, ("markLoc:%d", *markLoc));
  111.  
  112.     /*
  113.      *    get a pointer to the key in the record
  114.      */
  115.     key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
  116.     TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
  117.  
  118.     /*
  119.      *    check to see if the volume is mounted
  120.      */
  121.     if ((volRec = io_FindVolRec(pid->volid)) == NULL)    {
  122.  
  123.         SM_ERROR(TYPE_FATAL, Active->errno);
  124.     }
  125.  
  126.     /*
  127.      * Read in first page of file and grab node type
  128.      */
  129.     if ((nodeLink = bf_ReadPage(UserBufGroup, pid, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
  130.  
  131.         SM_ERROR(TYPE_FATAL, Active->errno);
  132.     }
  133.  
  134.     /*
  135.      *    get a pointer to the node page and the key
  136.      */
  137.     nodePage = (NODEPAGE *) nodeLink->bufFrame;
  138.     gotPid = &(nodePage->contents.keyPid.allKeys[*markLoc].key);
  139.  
  140.     /*
  141.      *    The markLoc may not be correct if other pages have been
  142.      *    inserted/deleted from the file.  So, search up first 
  143.      *    (since most likely and insert occurred), and then back.
  144.      */
  145.     if ( (*gotPid & LARGEMASK) != *key) {
  146.         foundLoc = -1; 
  147.         /* search up */
  148.         for(i = (int)(*markLoc)+1; i < nodePage->header.nodeCount; i++) {
  149.             if ( (nodePage->contents.keyPid.allKeys[i].key & LARGEMASK) == *key) {
  150.                 foundLoc = i;
  151.                 break;
  152.             }
  153.         }
  154.         if (foundLoc == -1) {
  155.             /* now search down */
  156.             for( i = (int)(*markLoc)-1; i >= 0; i--) {
  157.                 if ( (nodePage->contents.keyPid.allKeys[i].key & LARGEMASK) == *key) {
  158.                     foundLoc = i;
  159.                     break;
  160.                 }
  161.             }
  162.         }
  163.  
  164.         if (foundLoc == -1) {
  165.             /*
  166.              *    The key was not found.  Ideally we should search
  167.              *    the tree for the key since the undo is really a 
  168.              *    logical operation.  But, at this time we just 
  169.              *     don't undo it.  This is safe but could lead
  170.              *    to inefficiency in destroying the file.  But,
  171.              *    this problem can realistically only occur when
  172.              *    loading a large file (in one transaction) and
  173.              *    in that case the page will likely be deallocated in
  174.              *    the event of an abort.
  175.              */
  176.             /*SM_ERROR(TYPE_FATAL, esmINTERNAL);*/
  177.  
  178.             signalSemaphore( &(nodeLink->pageHash->semaphore) );
  179.             bf_UnfixPage(nodeLink, BF_DEFAULT, FALSE);
  180.             return;
  181.         }
  182.         markLoc = &foundLoc;
  183.         gotPid = &(nodePage->contents.keyPid.allKeys[*markLoc].key);
  184.     }
  185.  
  186.     /*
  187.      *    remove the mark 
  188.      */
  189.     *gotPid &= ~SETLARGE;
  190.  
  191.     /*
  192.      *    increment the lrc on the page
  193.      */
  194.     lrc = &(((NODEHEADER *) nodeLink->bufFrame)->lrc);
  195.     INCREMENT_LRC(lrc);
  196.  
  197.     /*
  198.      *    initialize the log information
  199.      */
  200.     recordInfo.type            = LOG_REC_TYPE_COMPENSATION;
  201.     recordInfo.action        = LOG_ACTION_NO_LARGE_OBJ_ON_PAGE;
  202.     recordInfo.imageCount    = 2;
  203.     recordInfo.actionPid    = pid;
  204.     recordInfo.actionLRC    = lrc;
  205.     recordInfo.imageSize[0] = sizeof(FOUR);
  206.     recordInfo.imageData[0] = (VOID *) markLoc;
  207.     recordInfo.imageSize[1] = sizeof(SHORTPID);
  208.     recordInfo.imageData[1] = (VOID *) key;
  209.     recordInfo.flags        = NOFLAGS;
  210.     recordInfo.nextUndoLSN    = recordHeader->previousLSN;
  211.  
  212.     /*
  213.      *    write the record to the log
  214.      */
  215.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, 
  216.                                     &recordInfo, &lsn, NOFLAGS)) < 0)    {
  217.         
  218.         SM_ERROR(TYPE_FATAL, Active->errno);
  219.     }
  220.  
  221.     /*
  222.      *    mark the page dependency
  223.      */
  224.     DEPEND_LOG(nodeLink->pageHash, forceMark, &lsn, lrc);
  225.  
  226.     /*
  227.      *    release  the page semaphore
  228.      */
  229.     signalSemaphore( &(nodeLink->pageHash->semaphore) );
  230.  
  231.     /*
  232.      *    release and dirty the page
  233.      */
  234.     bf_UnfixPage(nodeLink, BF_DEFAULT, TRUE);
  235. }
  236.